package com.lwj.liwanjia.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lwj.liwanjia.R;
import com.lwj.liwanjia.bean.DingBean05;
import com.lwj.liwanjia.bean.THTKLeftBean;
import com.lwj.liwanjia.config.OnClickPosition;
import com.lwj.liwanjia.view.activity.work.shang_jia.ding_dan.WuLiuActivity;
import com.lwj.liwanjia.view.activity.work.shang_jia.ding_dan.tui_huo_tui_kuan.ShenQingXiangQingActivity;
import com.lwj.liwanjia.view.activity.work.shang_jia.ding_dan.tui_huo_tui_kuan.THXQActivity;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by 001 on 2017/9/22.
 */

public class THTKLeftAdapter extends RecyclerView.Adapter<THTKLeftAdapter.ViewHolder> {


    private Context mContext;
    private List<DingBean05.DataBean> mList;
    private OnClickPosition clickPosition;

    public void setClickPosition(OnClickPosition clickPosition) {
        this.clickPosition = clickPosition;
    }

    public THTKLeftAdapter(Context mContext, List<DingBean05.DataBean> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public THTKLeftAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_tui_huo_tui_kuan_left, parent, false);

        final ViewHolder holder = new ViewHolder(view);

        return holder;
    }

    @Override
    public void onBindViewHolder(final THTKLeftAdapter.ViewHolder holder, final int position) {

        final DingBean05.DataBean bean = mList.get(position);

        Glide.with(mContext).load(bean.getGoods().getHead()).into(holder.circle_photo);
        String status = bean.getGoods().getStatus();
        if (status.equals("退款退货中") || status.equals("换货中") || status.equals("退款中")) {
            holder.tv_zhuangTai.setText(bean.getGoods().getStatus());
        } else {
            holder.tv_zhuangTai.setText(bean.getGoods().getStatus().replace("中", ""));
        }
        holder.tv_name.setText(bean.getGoods().getNick());
        holder.tv_content.setText(bean.getGoods().getCommodity().get(0).getCommodityname());

        holder.view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (clickPosition != null) {
                    clickPosition.clickPosition(position);
                }
                String state = bean.getGoods().getStatus();
                switch (state) {
                    case "已换货":
                    case "换货中":
                    case "退款退货中":
                    case "已退款退货":
                        Intent tuiKuanIntent = new Intent(mContext, WuLiuActivity.class);
                        tuiKuanIntent.putExtra("dingDanState", state);
                        tuiKuanIntent.putExtra("dingDanHao", bean.getGoods().getTradeId());
                        mContext.startActivity(tuiKuanIntent);
                        break;
                    case "正在申请(已完成)":
                    case "正在申请(退款中)":
                    case "正在申请(换货中)":
                    case "正在申请(退款退货中)":
                    case "正在申请(待发货)":
                        Intent intent02 = new Intent(mContext, ShenQingXiangQingActivity.class);
                        intent02.putExtra("tuiState", state);
                        intent02.putExtra("id", bean.getGoods().getTradeId());
                        mContext.startActivity(intent02);
                        break;
                }

            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        View view;
        CircleImageView circle_photo;
        TextView tv_zhuangTai;
        TextView tv_name;
        TextView tv_content;

        public ViewHolder(View itemView) {
            super(itemView);

            view = itemView;
            circle_photo = (CircleImageView) itemView.findViewById(R.id.circle_photo);
            tv_zhuangTai = (TextView) itemView.findViewById(R.id.tv_zhuangTai);
            tv_name = (TextView) itemView.findViewById(R.id.tv_name);
            tv_content = (TextView) itemView.findViewById(R.id.tv_content);
        }
    }
}
